/* terminal.hh
* This file is part of ncursesxx library
* Copyright (c) 2003,2004 by Stanislav Ievlev
*
* This file is covered by the GNU Library General Public License,
* which should be included with libncursesxx as the file COPYING.
*/
#ifndef NCURSESXX_TERMINAL_HH__
#define NCURSESXX_TERMINAL_HH__

#include <term.h>
#include <curses.h>

#include <ncurses/sysio_filebuf.hh>

namespace ncurses
{
	typedef short color_t;
	typedef chtype attr_t;

	/**
	 * ncurses terminal object.
	 * unfortunately, we cannot made templates for CharT, 'cause
	 * terminfo library has too bad design for tputs,vidputs functions
	 * (limited type of the callback, what about void* userdata pointer?)
	 * @todo made as a template when terminfo API will be ready
	 */
	class terminal
	{
	public:
		typedef ext::sysio_filebuf<char>	buffer_type;
		/**
		 * init terminal, open descriptor pointing to file descriptor
		 */
		terminal(buffer_type& buf, const char *termname = 0);
		~terminal();

		//send control sequences to terminal to set foreground color and attributes
		void set_attr(attr_t mode = A_NORMAL);  /**< set terminal attributes */
		void set_fg_color(color_t color = COLOR_WHITE); /**< set foreground color */
		void set_fg(color_t color, attr_t mode = A_NORMAL); /**< set foreground color and attributes */

		color_t	color() const; /**< return current terminal color */
		attr_t	attr() const; /**< return current terminal attributes */

		int colors_num() const; /**< return number of possible colors */

		void reset_colors(); //reset all colors and color pairs
	private:
		buffer_type	*buf_; /**< pointer to output buffer */
		TERMINAL	*term_; /**< ncurses terminal object */
		color_t	color_; /**< current terminal color */
		attr_t	attr_; /**< current terminal attributes */
		int	colors_num_; /**< maximum number of the colors */
	};
}

#endif
